import React from 'react'

const {
    useState
} = React;


 const UseState = (props)=>{

     const [num,setNum] = useState(11);
     const [obj,setObj] = useState({
         age:18,
         sex:'男'
     })

     const changeNum = ()=>{
         setTimeout(()=>{
             setNum((num)=>{
                 return num+1
             })
         },3000)
     }
    return (
        <div>
            {num}
            <br/>
            <button onClick={ changeNum }>按钮A</button>
            <button onClick={ ()=>setNum(num+1) }>按钮B</button>
            <br/>
            <p>
                {
                    obj.age
                }
            </p>
            <button onClick={()=>{
                setObj( {
                    age:obj.age + 1
                })
            } }>修改年龄</button>
        </div>
    )
}

export default UseState